<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

<body>
    <input type="text"> <br>
    <input type="text"> <br>
    <input type="text"> <br>
    <input type="text"> <br>
    <input type="text"> <br>
    <input type="text"> <br>
    <input type="text"> <br>
    <input type="button" value="button"> <br>

    <script>
        var inputs = document.getElementsByTagName("input");

        for(var i = 0; i < inputs.length; i++) {
            var input = inputs[i];

            if (input.type === "text") {
                //注册事件
                //获取焦点 focus
                input.onfocus = focusHandle;
                //失去焦点 blur
                input.onblur = blurHandle;
            }
        }

        function focusHandle() {
            this.style.backgroundColor = "lightyellow";
        }

        function blurHandle(){
            this.style.backgroundColor = "";
        }
    </script>

</body>

</html>